<!DOCTYPE html>
<html lang="en">
<head>
    
    <meta charset="utf-8">
    <title>Home - Documentation</title>
    
    
    <script src="scripts/prettify/prettify.js"></script>
    <script src="scripts/prettify/lang-css.js"></script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc.css">
    <script src="scripts/nav.js" defer></script>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>

<input type="checkbox" id="nav-trigger" class="nav-trigger" />
<label for="nav-trigger" class="navicon-button x">
  <div class="navicon"></div>
</label>

<label for="nav-trigger" class="overlay"></label>

<nav >
    
    <input type="text" id="nav-search" placeholder="Search" />
    
    <h2><a href="index.html">Home</a></h2><h2><a href="https://github.com/axolo/egg-sendmail" target="_blank" class="menu-item" id="website_link" >GitHub</a></h2><h3>Classes</h3><ul><li><a href="Sendmail.html">Sendmail</a><ul class='methods'><li data-type='method' style='display: none;'><a href="Sendmail.html#send">send</a></li><li data-type='method' style='display: none;'><a href="Sendmail.html#template">template</a></li></ul></li></ul>
</nav>

<div id="main">
    

    



    


    <section class="package">
        <h3> </h3>		
    </section>









    



    <section class="readme usertext">
        <article><h1>egg-sendmail</h1>
<p><a href="https://nodemailer.com">Nodemailer</a> Egg.js插件。</p>
<h2>安装插件</h2>
<pre class="prettyprint source lang-bash"><code>npm i @axolo/egg-sendmail --save
</code></pre>
<h2>开启插件</h2>
<pre class="prettyprint source lang-js"><code>// config/plugin.js
exports.sendmail = {
  enable: true,
  package: '@axolo/egg-sendmail',
};
</code></pre>
<h2>详细配置</h2>
<pre class="prettyprint source lang-js"><code>// {app_root}/config/config.default.js
exports.sendmail = {
  client: {
    from: '&quot;no-reply&quot; &lt;no-reply@localhost>',  // 发件人
    smtp: { // 邮件发送服务器配置
      host: 'smtp.local.host', // 主机
      port: 465, // 端口
      secure: true, // 是否启用SSL
      auth: { // 授权信息
        user: 'no-reply@local.host', // 用户名
        pass: 'password', // 密码
      },
    },
  },
};
</code></pre>
<p>请到 <a href="config/config.default.js">config/config.default.js</a> 查看详细配置项说明。</p>
<h2>例子</h2>
<pre class="prettyprint source lang-js"><code>// /app/controller/mail.js
class MailController extends Controller {
  async index() {
    const { app, ctx } = this;
    const { sendmail } = app;
    const to = 'to@email.com';
    const data = {
      buyerName: '方跃明',
      statusMsg: '开票成功',
      invoiceDate: '2020-03-10 15:33:32',
      invoiceLine: '电子增值税普通发票',
      invoiceFileUrl: 'https://www.baidu.com',
    };
    const message = {
      subject: '电子发票{{ statusMsg }}',
      html: `**{{ buyerName }}，您好：**

您于{{ invoiceDate }}申请的{{ invoiceLine }} {{ statusMsg }}，请及时查收。

点击 [此处]({{ invoiceFileUrl }}) 下载电子发票。

若无法下载，请复制以下地址到浏览器中打开：{{ invoiceFileUrl }}`,
    };
    const result = await sendmail.send({ to }, message, data);
    ctx.body = result;
  }
}

module.exports = MailController;
</code></pre>
<h2>接口文档</h2>
<p><a href="https://axolo.github.io/egg-sendmail">文档</a></p>
<h2>提问交流</h2>
<p>请到 <a href="https://github.com/axolo/egg-sendmail/issues">egg issues</a> 异步交流。</p>
<h2>License</h2>
<p><a href="LICENSE">MIT</a></p></article>
    </section>






    
    
</div>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> on Wed Mar 11 2020 10:54:30 GMT+0800 (中国标准时间) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
</footer>

<script>prettyPrint();</script>
<script src="scripts/polyfill.js"></script>
<script src="scripts/linenumber.js"></script>

<script src="scripts/search.js" defer></script>


<script src="scripts/collapse.js" defer></script>


</body>
</html>